<script setup>
import myAxios from "@/plugins/myAxios";
import {onMounted, ref} from "vue";
import {Message} from "@arco-design/web-vue";

const columns = [
  {
    title: '顾客姓名',
    dataIndex: 'name',
  },{
  title: '菜品名称',
  dataIndex: 'dishName',
}, {
  title: '数量',
  dataIndex: 'quantity',
  render: ({ record }) => {
    return `${record.quantity}份`;
  }
}, {
  title: '花费',
  dataIndex: 'cost',
  render: ({ record }) => {
    return `${record.cost}￥`;
  }
}, {
  title: '下单时间',
  dataIndex: 'time',
}];
const data =ref([])
const adminInfo = ref({
  id:'',
  name:'',
  phone:'',
  password:''
});

onMounted(async() => {

  const res1 = await myAxios.get('/admin/current')
  adminInfo.value = res1.data.data
  //如果不是管理员，就只查询当前用户的消费信息
  if (adminInfo.value.phone == null){
    const customerId = localStorage.getItem("customerId")
    const res = await myAxios.get(`/menu/order/info/${customerId}`)
    if (Array.isArray(res.data.data)){
      res?.data.data.forEach(item => {
        data.value.push({
          dishName: item.dishName,
          name: item.name,
          ...item.orders
        })
      })
      console.log("data:",res.data.data)
      Message.success("获取成功")
    }else{
      Message.error("没有数据")
    }
    //如果是管理员，就查询所有顾客消费信息
  }else{
    const res = await myAxios.get('/menu/order/info/list')
    if (Array.isArray(res.data.data)){
      res?.data.data.forEach(item => {
        data.value.push({
          dishName: item.dishName,
          name: item.name,
          ...item.orders
        })
      })
      console.log("data:",res.data.data)
      Message.success("获取成功")
    }else{
      Message.error("没有数据")
    }
  }
})
const pagination = {pageSize: 9}
</script>

<template>
  <div>
    <a-table :columns="columns" :data="data" :pagination="pagination" style="font-style: normal;font-size: 30px">
    </a-table>
  </div>
</template>

<style scoped>

</style>